package com.panomedic.utils;

import java.util.List;
import java.util.ArrayList;


public class StringUtils {
    

    public static String toString(double value, int numberOfDecimals) 
    {
        String result = Double.toString(value);
        
        if (result.contains(".")) 
        {
            int nDecimals = Math.min(numberOfDecimals, result.length() - result.indexOf('.'));
            if (result.indexOf('.') + nDecimals + 1 < result.length())
                return result.substring(0, result.indexOf('.') + nDecimals + 1);
            return result.substring(0, result.length());
        }
        return result;
    }
    
    public static ArrayList<String> fromStringArrayToList(String[] strings) 
    {
        ArrayList<String> result = new ArrayList<String>();
        for (String s : strings)
            result.add(s);
        return result;
    }
    
    public static String fromObjectArrayToString(Object[] strings) 
    {
        StringBuilder objStringBuilder = new StringBuilder();

        for (int i = 0; i < strings.length; i++)
            objStringBuilder.append(strings[i]);

        return objStringBuilder.toString();
    }

    /**
     * Returns a string with concatenation of argument array
     * 
     * @param strings
     *            strings
     * @return concatenation of argument array
     */
    public static String getString(Object... strings) {
        StringBuilder objStringBuilder = new StringBuilder();

        for (int i = 0; i < strings.length; i++)
            objStringBuilder.append(strings[i]);

        return objStringBuilder.toString();
    }    
}
